package cn.tedu.ivos.dictoption.service.impl;

import cn.tedu.ivos.dictoption.mapper.DictOptionMapper;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos.dictoption.pojo.entity.DictOption;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class DictOptionServiceImpl implements DictOptionService {
    @Autowired
    DictOptionMapper dictOptionMapper;

    @Override
    public List<DictOptionVO> selectDictOption(DictOptionQuery dictOptionQuery) {
        log.debug("开始处理【查询字典项】的业务，参数：{}", dictOptionQuery);
        List<DictOptionVO> list = dictOptionMapper.selectDictOption(dictOptionQuery);

        return list;
    }

    @Override
    public void saveDictOption(DictOptionSaveParam dictOptionSaveParam) {
        log.debug("开始处理【保存字典项】的业务，参数：{}", dictOptionSaveParam);
        DictOption dictOption = new DictOption();
        BeanUtils.copyProperties(dictOptionSaveParam, dictOption);
        if(dictOption.getId() == null){
            dictOption.setCreateTime(new Date());
            dictOptionMapper.insertDictOption(dictOption);
        }else {
            dictOption.setUpdateTime(new Date());
            dictOptionMapper.updateDictOption(dictOption);
        }

    }

    @Override
    public void deleteDictOption(Long id) {
        log.debug("开始处理【删除字典项】的业务，参数：{}", id);
        dictOptionMapper.deleteDictOption(id);
    }
}
